package com.atguigu.gmall.pay;

import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.alipay.api.response.AlipayTradePagePayResponse;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: 李旭
 * @Time: 15:25
 * @Description:
 *
 *   测试与支付宝之间连接
 *     测试数据
 */
public class AlipayDemo {


    //1:引入阿里 SDK 工具包   微信导入SDK
    public static void main(String[] args) throws Exception{
        //1:创建Alipay客户端
        //下面的七个参数要去沙箱环境找
        AlipayClient alipayClient = new DefaultAlipayClient(//SpringBoot SpringCloud Gateway
                "https://openapi.alipaydev.com/gateway.do",//走沙箱的
                "2016102100732915",
                "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCqV8BRoEPsjCHPGjNst3qn+Q8AKmzsEiRwMwl8ON73cG587Sc4xNi4+AIxrPzWUk8dPnXUlTXsYh6rj9guGtQKp/rpzMYbcGstwk2s4NpjoIHiTguh4qEL/lQWTQNl2QLsBZm8AicgYdvxnWvCu7uNCEsCLlnkipuvqL/ZvFGGn9p/X/nmV27RC3jSbYeMPV6rilk76QIjNRy841NHTpS27j/fLyfav0aaS7qNWqnvrmQRwY7Ffv66NTYRQWaG51zqxIaZYoH4AxYe8ulmeY+82cQVJxf7z0abfdfTZoDjE4QQlk3IWCXrKmtEjgMJiCk11yFpqmg0JMFug50ZQkrpAgMBAAECggEAKw+Jv1irMwXtmgP+kfID4Kh2IU2YQUkIyxAryqo5uwVB+PSeYJxqSL/xFgur0qX19+eNM9MQUZQwOqBfPrBrf9Ic/LNWNSODBItExXoF2v99Ne8Sw7adjYGaUhTf0gQ819tGlJ9asrXqOrbXwd9hNvKsu31qHfroBky7SthvJ3+hgpwzhVtuW36wDB/xtgE0jw+rworcIwfV6KYMX/55sOpBymwfSoyCcqc+cuKgWZUkBHM4pR+AEjY/g11rjCFovE6ybv2FN+3xj0csJCtYEOvC3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7Feh3VoDilcDpGtuKo5l7YRVnGSyQTq0pQjMFYi/wKGFGHAA37Wl2L/AMaGpT6CJncSqcAJssY61qmz/o9lw+hRq6KBfdktl4xm0d5f+uMgCLKqa6bYbFyG7vNZszGJ6yW2n6fFbZ0B4PgPXfrRFVG+OS204bi7sGDba6DuJPPuk8B/gkVoDkmKHNRnLXZi74jyZROlEXKr8JElZqpT6RODkKAmIRCGlQrAadUntgmymguRlN2K+TfSNIigY1FRekb/BudYhlbA5QIDAQAB",
                "RSA2");
        //上面七个参数是公共参数   每次请求都要带着的参数
       //======================================
        //下面有四个参数是请求参数 是每次请求必须带着的
        AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();

        Map map = new HashMap();
        //
        map.put("out_trade_no","wggnhtrytryhjiu6ythjuiuy5retjuiu");
        map.put("product_code","FAST_INSTANT_TRADE_PAY");
        map.put("total_amount","0.01");
        map.put("subject","不为什么就是测试");
        request.setBizContent(JSONObject.toJSONString(map));
        AlipayTradePagePayResponse response = alipayClient.pageExecute(request);
        if(response.isSuccess()){
            System.out.println(response.getBody());
            System.out.println("调用成功");
        } else {
            System.out.println("调用失败");
        }


/*
  <form name="punchout_form" method="post" action="https://openapi.alipaydev.com/gateway.do?charset=UTF-8&method=alipay.trade.page.pay&sign=eh7pX21uym4Qr3tkVU2WyI4uLU4cVkTewjSyMWELwKKaocNobgdpSkhaY0PJkXhmXsg2drRznuL4jcNf25J8JRVFeOHQU1Et2CPsK6zeLp6eW3g7wK5v4dW7ZQCS4rY7erJVxPYaCHS3FB%2FehasqRDcnReDYDZKrqvP%2BFfHVJ1ZerIKB4CprBNoSROKcMxOekAkFWrn47hkmZ3pEYO2nFmT3IgUQf1v68%2BoA0ydiVxiFdvBoMxFjTQzP5nTUUVlAsSwBl0%2FAUHzkX4f7JZmNtdiBCFNf4JjaLjbf7j72pnFXO9EW2Q0ujLwGyYEhyy18IcXxRmCehn3eVgyCVmx9iA%3D%3D&version=1.0&app_id=2016102100732915&sign_type=RSA2&timestamp=2021-04-23+16%3A09%3A43&alipay_sdk=alipay-sdk-java-4.8.73.ALL&format=json">
<input type="hidden" name="biz_content" value="{&quot;out_trade_no&quot;:&quot;wggnhtrytryhjiu6ythjuiuy5retjuiu&quot;,&quot;total_amount&quot;:&quot;0.01&quot;,&quot;subject&quot;:&quot;不为什么就是测试&quot;,&quot;product_code&quot;:&quot;FAST_INSTANT_TRADE_PAY&quot;}">
<input type="submit" value="立即支付" style="display:none" >
</form>
<script>document.forms[0].submit();</script>
                调用成功*/





    }
}
